package com.example.cici.cclight.util;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;

public class CustomViews extends View {

    private Paint mPaint;
    private Context mContext;
    private int screenWidth;
    private int screenHeight;
    private int radial = 350;


    public CustomViews(Context context) {
        super(context);
        init();
    }



    public CustomViews(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        init();
    }

    private void init() {
        mPaint = new Paint();
        //设置画笔为抗锯齿
        mPaint.setAntiAlias(true);
//        //设置颜色
//        mPaint.setColor(Color.RED);
        mPaint.setColor(Color.argb(50,255,0,0));
        /** 
         * 画笔样式分三种：1.Paint.Style.STROKE：描边 2.Paint.Style.FILL_AND_STROKE：描边并填充 
         * 3.Paint.Style.FILL：填充 
         */
        mPaint.setStyle(Paint.Style.FILL);
//        设置描边的粗细
        mPaint.setStrokeWidth(2);
//        获取屏幕的宽高？
        WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        screenWidth = display.getWidth();
        screenHeight = display.getHeight();
    }

    protected void onDraw(Canvas canvas){
        super.onDraw(canvas);
        canvas.drawCircle(screenWidth/2,screenHeight/3,radial,mPaint);
    }
//    @Override
//    public void run() {
//        while (true){
//            if (radial<=170){
//                radial += 20;
//                postInvalidate();
//            }else {
//                radial = 50;
//            }
//            try {
//                Thread.sleep(200);
//            }catch (InterruptedException e){
//                e.printStackTrace();
//            }
//        }
//    }
}
